home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / virtmem.exe / VIRTUMEM.INT < prev    next >
Text File  |  1992-10-08  |  4KB  |  136 lines

  1. Unit VirtuMem;                                                                {Virtual memory manager -modified LRU}
  2.  
  3. {$F+}
  4. {$R+}
  5. {$B-}
  6. {$O-}
  7.  
  8. Interface
  9.  
  10. {THE FOLLOWING CONSTANTS, VARIABLES AND ROUTINES ARE MEANT TO BE USED BY
  11.  ANY PROGRAM.  THEY ARE THE ESSENTIAL INTERFACE OF THE VIRTUMEM UNIT, ALONG
  12.  WITH SOME SUPPORT TO GET STATUS INFORMATION.}
  13.  
  14. Const
  15.  
  16.      Null=0;
  17.      Clen=0;
  18.      Dirt=1;
  19.      Stay=2;
  20.      BookOpen:Boolean=FALSE;
  21.      VVersion=1.0;
  22.      VVersionDate='February 27, 1992';
  23.  
  24. Var
  25.  
  26.      VMem          :Boolean;           {Virtual memory is active.}
  27.      NotSoRealTime :LongInt;           {Number of calls to virtual memory system}
  28.      Missy         :Integer;           {Number of times a reference was not found in real memory}
  29.      NewCount      :LongInt;           {Number of calls to ANew}
  30.      DepossessCount:LongInt;           {Number of calls to Depossess}
  31.      ExpandedCount :LongInt;           {Number of times a read was done from an expanded memory page.}
  32.      SwapCount     :LongInt;           {Number of times an expanded memory page was swapped with a real memory page.}
  33.      Unstaycount   :LongInt;           {Number of calls to Unstay}
  34.  
  35. {Initialize Virtual memory system.}
  36. {$IFDEF USEEMS}
  37. Procedure OpenBook(EMSSuppress:Boolean);
  38. {$ELSE}
  39. Procedure OpenBook;
  40. {$ENDIF}
  41.  
  42. {Allocate a virtual memory block.}
  43. Function ANew(Size : Word):LongInt;
  44.  
  45. {Reference a virtual memory block.}
  46. Function R(Virt : LongInt; Mucky : Integer):Pointer;
  47.  
  48. {Deallocate a virtual memory block.}
  49. Procedure Depossess(var Virt:LongInt;Biggness:Word);
  50.  
  51. {Return the number of pages that are held in real memory.}
  52. Function CountStay:Integer;
  53.  
  54. {Free a page that is held in real memory.}
  55. Procedure UnStay(Virt : LongInt);
  56.  
  57. {Shut down the virtual memory system.}
  58. Procedure CloseBook;
  59.  
  60.  
  61. {THE FOLLOWING CONSTANTS, TYPES, VARIABLES AND ROUTINES ARE INCLUDED IN THE
  62.  INTERFACE SECTION OF VIRTUMEM ONLY BECAUSE THEY ARE ALSO USED BY SUCH
  63.  UNITS AS "SECONDAR" WHICH DO SOME LOW LEVEL MANIPULATION OF THE NORMAL
  64.  VIRTUMEM STRUCTURE.  THESE ARE NOT NORMALLY USED BY OTHER PROGRAMMERS.}
  65.  
  66. Const
  67.  
  68. {$IFDEF DEBUG}
  69.      PageSize    =1023;
  70. {$ELSE}
  71.      PageSize    =8191;
  72. {$ENDIF}
  73.      MaxPage     =511;                                                         {Max page number in memory resident table}
  74.      C           =FALSE;
  75.      D           =TRUE;
  76.      DirtyMarkup =512;
  77.      NoPage      = 65535;
  78.      PagePerXPage=(16*1024) div (PageSize+1);
  79.      HighFreeListElement = 511;
  80.  
  81. Type
  82.  
  83.      DataBlockPtr=^DataBlockArr;
  84.      DataBlockArr=Array[0..PageSize] of Byte;
  85.  
  86.      PageFramePtr=^PageFrameRec;
  87.      PageFrameRec=
  88.         Record
  89.           Dirty      :Boolean;
  90.           Priority   :LongInt;
  91.           StayCount  :Integer;
  92.           Data       :DataBlockPtr;
  93.           Last       :PageFramePtr;
  94. {$IFDEF USEEMS}
  95.           LogicalPage:Word;
  96.           Offset     :Word;
  97. {$ENDIF}
  98.           PageNum    :Integer;
  99.         End;
  100.  
  101.      TableEntry =
  102.         Record
  103.           Frame     : PageFramePtr;
  104.           DirtE     : Boolean;
  105.           PageNum   : Integer;
  106.         End;
  107.  
  108. Var
  109.  
  110.      PageTable     :Array[0..MaxPage] of TableEntry;
  111.      HighFrame     :PageFramePtr;
  112.      HighPage      :Integer;
  113.      PageInMem     :Integer;
  114.      PgTable       :File of TableEntry;
  115.      VirtualMemory :File;
  116.      Traver        :PageFramePtr;
  117.      Bound         :LongInt;
  118.      V             :DataBlockArr;
  119.  
  120. {$IFDEF CALLPROF}
  121.      CallBin       :Array[0..511] of LongInt;
  122. {$ENDIF}
  123.  
  124. Procedure SetFreeList;
  125. Procedure PageTableFlush;
  126. Procedure VirtualMemoryFlush;
  127. {$IFDEF VERYLARGE}
  128. Procedure GetEntry(PageNumber : Integer);
  129. {$ENDIF}
  130. {$IFDEF USEEMS}
  131. Function PageSegment(LogicalPageNum:Word):Word;
  132. Procedure MapIn(LogicalPage:Word);
  133. {$ENDIF}
  134. Procedure UnsetFreeList;
  135. Procedure Dumpossess;{Write the free list to the screen.}
  136.